﻿using System;

namespace CXW.Core.Services
{
    /// <summary></summary>
    public abstract class ServiceManager
    {
        volatile static ServiceManager instance = new DefaultServiceManager();

        /// <summary>
        /// Gets the static ServiceManager instance.
        /// </summary>
        public static ServiceManager Instance
        {
            get { return instance; }
            set
            {
                if (value == null) { throw new ArgumentNullException(); }
                instance = value;
            }
        }

        /// <summary>
        /// Gets the logging service.
        /// </summary>
        public virtual ILoggingService LoggingService { get; }

        /// <summary>
        /// Gets the message service.
        /// </summary>
        public virtual IMessageService MessageService { get; }
    }

    sealed class DefaultServiceManager : ServiceManager
    {
        static ILoggingService loggingService = new TextWriterLoggingService(new DebugTextWriter());
        static IMessageService messageService = new TextWriterMessageService(Console.Out);

        public override ILoggingService LoggingService
        {
            get { return loggingService; }
        }
        public override IMessageService MessageService
        {
            get { return messageService; }
        }
    }
}
